<template>
	<view class="container">
		<uv-sticky bgColor="#fff">
			<uv-tabs @change="change" :current="currentIndex" :scrollable="false" :list="list" @click="click"></uv-tabs>
		</uv-sticky>
		<view class="list">
			<view class="list-item" v-for="item in dataList">
				<view class="list-item-title">
					{{ item.title }}
				</view>
				<image @click="preview(item)" :src="item.imgUrl" mode="aspectFill"></image>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [
				{
					name: '全部'
				},
				{
					name: '推荐'
				},
				{
					name: '风景'
				},
				{
					name: '美女'
				}
			],
			dataList: [],
			currentIndex: 0
		};
	},
	methods: {
		click(e) {
			this.activeIndex = e.index;
			if (e.name == '全部') {
				this.getList(e.name);
			} else if (e.name == '推荐') {
				this.getList(e.name);
			} else if (e.name == '风景') {
				this.getList(e.name);
			} else if (e.name == '美女') {
				this.getList(e.name);
			}
		},
		change(e) {
			this.currentIndex = e.index;
		},
		getList(e) {
			uniCloud
				.callFunction({
					name: 'getImgList',
					data: {
						type: e
					}
				})
				.then((res) => {
					this.dataList = res.result.data;
				});
		},
		// 预览图片
		preview(item) {
			uni.previewImage({
				urls: [item.imgUrl]
			});
		}
	},
	onLoad() {},
	onShow() {
		this.currentIndex = 0;
		this.getList(this.list[this.currentIndex].name);
	}
};
</script>

<style lang="scss" scoped>
.container {
	.list {
		padding: 20rpx;
		box-sizing: border-box;
		display: flex;
		flex-wrap: wrap;
		gap: 20rpx;
		&-item {
			border-radius: 24rpx;
			background-color: #e2e2e2;
			padding: 40rpx 20rpx;
			box-sizing: border-box;
			width: 100vw;
			display: flex;
			flex-direction: column;
			align-items: center;
			gap: 20rpx;
			&-title {
				font-weight: bold;
			}
		}
	}
}
</style>
